CJPEG(1) CJPEG(1) NAME cjpeg−compressanimagefiletoaJPEGfile SYNOPSIS cjpeg[options][filename] DESCRIPTION cjpegcompressesthenamedimagefile,orthestandardinputifnofileisnamed,andproducesa JPEG/JFIFfileonthestandardoutput.Thecurrentlysupportedinputfileformatsare:PPM (PBMPLUScolorformat),PGM(PBMPLUSgray-scaleformat),BMP,GIF,Targa,andRLE (UtahRasterToolkitformat).(RLEissupportedonlyiftheURTlibraryisavailable.) OPTIONS Allswitchnamesmaybeabbreviated;forexample,−grayscalemaybewritten−grayor−gr. Mostofthe"basic"switchescanbeabbreviatedtoaslittleasoneletter.Upperandlowercase areequivalent(thus−GIFisthesameas−gif).Britishspellingsarealsoaccepted(e.g., −greyscale),thoughforbrevitythesearenotmentionedbelow. Thebasicswitchesare: −qualityN Scalequantizationtablestoadjustimagequality.Qualityis0(worst)to100(best); defaultis75.(Seebelowformoreinfo.) −grayscale CreatemonochromeJPEGfilefromcolorinput.BesuretousethisswitchwhencompressingagrayscaleGIFfile,becausecjpegisn’tbrightenoughtonoticewhetheraGIF fileusesonlyshadesofgray.Bysaying−grayscale,you’llgetasmallerJPEGfilethat takeslesstimetoprocess. −optimize Performoptimizationofentropyencodingparameters.Withoutthis,defaultencoding parametersareused.−optimizeusuallymakestheJPEGfilealittlesmaller,butcjpeg runssomewhatslowerandneedsmuchmorememory.Imagequalityandspeedofdecompressionareunaffectedby−optimize. −targa InputfileisTargaformat.Targafilesthatcontainan"identification"fieldwillnotbe automaticallyrecognizedbycjpeg;forsuchfilesyoumustspecify−targatomakecjpeg treattheinputasTargaformat.FormostTargafiles,youwon’tneedthisswitch. The−qualityswitchletsyoutradeoffcompressedfilesizeagainstqualityofthereconstructed image:thehigherthequalitysetting,thelargertheJPEGfile,andtheclosertheoutputimage willbetotheoriginalinput.Normallyyouwanttousethelowestqualitysetting(smallestfile) thatdecompressesintosomethingvisuallyindistinguishablefromtheoriginalimage.Forthispurposethequalitysettingshouldbebetween50and95;thedefaultof75isoftenaboutright.If youseedefectsat−quality75,thengoup5or10countsatatimeuntilyouarehappywiththe outputimage.(Theoptimalsettingwillvaryfromoneimagetoanother.) −quality100willgenerateaquantizationtableofall1’s,eliminatinglossinthequantizationstep (butthereisstillinformationlossinsubsampling,aswellasroundofferror).Thissettingis mainlyofinterestforexperimentalpurposes.Qualityvaluesaboveabout95arenotrecommendedfornormaluse;thecompressedfilesizegoesupdramaticallyforhardlyanygaininoutputimagequality. Intheotherdirection,qualityvaluesbelow50willproduceverysmallfilesoflowimagequality. Settingsaround5to10mightbeusefulinpreparinganindexofalargeimagelibrary,forexample.Try−quality2(orso)forsomeamusingCubisteffects.(Note:qualityvaluesbelowabout 25generate2-bytequantizationtables,whichareconsideredoptionalintheJPEGstandard. cjpegemitsawarningmessagewhenyougivesuchaqualityvalue,becausesomecommercial JPEGprogramsmaybeunabletodecodetheresultingfile.Use−baselineifyouneedtoensure 12December1994 1 CJPEG(1) CJPEG(1) compatibilityatlowqualityvalues.) Switchesforadvancedusers: −dctint UseintegerDCTmethod(default). −dctfast UsefastintegerDCT(lessaccurate). −dctfloat Usefloating-pointDCTmethod.Thefloatmethodisveryslightlymoreaccuratethan theintmethod,butismuchslowerunlessyourmachinehasveryfastfloating-pointhard-ware.Alsonotethatresultsofthefloating-pointmethodmayvaryslightlyacross machines,whiletheintegermethodsshouldgivethesameresultseverywhere.Thefast integermethodismuchlessaccuratethantheothertwo. −restartN EmitaJPEGrestartmarkereveryNMCUrows,oreveryNMCUblocksif"B"is attachedtothenumber.−restart0(thedefault)meansnorestartmarkers. −smoothN Smooththeinputimagetoeliminateditheringnoise.N,rangingfrom1to100,indicates thestrengthofsmoothing.0(thedefault)meansnosmoothing. −maxmemoryN Setlimitforamountofmemorytouseinprocessinglargeimages.Valueisinthousands ofbytes,ormillionsofbytesif"M"isattachedtothenumber.Forexample,−max4m selects4000000bytes.Ifmorespaceisneeded,temporaryfileswillbeused. −outfilename Sendoutputimagetothenamedfile,nottostandardoutput. −verbose Enabledebugprintout.More−v’sgivemoreoutput.Also,versioninformationisprinted atstartup. −debug Sameas−verbose. The−restartoptioninsertsextramarkersthatallowaJPEGdecodertoresynchronizeaftera transmissionerror.Withoutrestartmarkers,anydamagetoacompressedfilewillusuallyruin theimagefromthepointoftheerrortotheendoftheimage;withrestartmarkers,thedamageis usuallyconfinedtotheportionoftheimageuptothenextrestartmarker.Ofcourse,therestart markersoccupyextraspace.Werecommend−restart1forimagesthatwillbetransmitted acrossunreliablenetworkssuchasUsenet. The−smoothoptionfilterstheinputtoeliminatefine-scalenoise.Thisisoftenusefulwhencon-vertingGIFfilestoJPEG:amoderatesmoothingfactorof10to50getsridofditheringpatterns intheinputfile,resultinginasmallerJPEGfileandabetter-lookingimage.Toolargeasmooth-ingfactorwillvisiblyblurtheimage,however. Switchesforwizards: −arithmetic UsearithmeticcodingratherthanHuffmancoding.(Notcurrentlysupportedforlegal reasons.) −baseline ForceabaselineJPEGfiletobegenerated.Thisclampsquantizationvaluesto8bits evenatlowqualitysettings. 12December1994 2 CJPEG(1) CJPEG(1) −nointerleave GeneratenoninterleavedJPEGfile(notyetsupported). −qtablesfile Usethequantizationtablesgiveninthespecifiedfile.Thefileshouldcontainonetofour tables(64valueseach)asplaintext.Commentsprecededby’#’maybeincludedinthe file.Thetablesareimplicitlynumbered0,1,etc.If−qualityNisalsospecified,thevaluesinthefilearescaledaccordingtocjpeg’squalityscalingcurve. −qslotsN[,...] Selectwhichquantizationtabletouseforeachcolorcomponent.Bydefault,table0is usedforluminanceandtable1forchrominancecomponents. −sampleHxV[,...] SetJPEGsamplingfactors.IfyouspecifyfewerH/Vpairsthantherearecomponents, theremainingcomponentsaresetto1x1sampling.Thedefaultsettingisequivalentto −sample2x2. The"wizard"switchesareintendedforexperimentationwithJPEG.Ifyoudon’tknowwhatyou aredoing,don’tusethem.Youcaneasilyproducefileswithworseimagequalityand/orpoorer compressionthanyou’llgetfromthedefaultsettings.Furthermore,theseswitchesshouldnotbe usedwhenmakingfilesintendedforgeneraluse,becausenotallJPEGimplementationswillsupportunusualJPEGparametersettings. EXAMPLES ThisexamplecompressesthePPMfilefoo.ppmwithaqualityfactorof60andsavestheoutputas foo.jpg: cjpeg−quality60foo.ppm>foo.jpg HINTS ColorGIFfilesarenottheidealinputforJPEG;JPEGisreallyintendedforcompressingfullcolor(24-bit)images.Inparticular,don’ttrytoconvertcartoons,linedrawings,andotherimages thathaveonlyafewdistinctcolors.GIFworksgreatonthese,JPEGdoesnot.Ifyouwantto convertaGIFtoJPEG,youshouldexperimentwithcjpeg’s−qualityand−smoothoptionsto getasatisfactoryconversion.−smooth10orsoisoftenhelpful. AvoidrunninganimagethroughaseriesofJPEGcompression/decompressioncycles.Image qualitylosswillaccumulate;aftertenorsocyclestheimagemaybenoticeablyworsethanitwas afteronecycle.It’sbesttousealosslessformatwhilemanipulatinganimage,thenconvertto JPEGformatwhenyouarereadytofiletheimageaway. The−optimizeoptiontocjpegisworthusingwhenyouaremakinga"final"versionforposting orarchiving.It’salsoawinwhenyouareusinglowqualitysettingstomakeverysmallJPEG files;thepercentageimprovementisoftenalotmorethanitisonlargerfiles. ENVIRONMENT JPEGMEM Ifthisenvironmentvariableisset,itsvalueisthedefaultmemorylimit.Thevalueis specifiedasdescribedforthe−maxmemoryswitch.JPEGMEMoverridesthedefault valuespecifiedwhentheprogramwascompiled,anditselfisoverriddenbyanexplicit −maxmemory. SEEALSO djpeg(1),rdjpgcom(1),wrjpgcom(1) ppm(5),pgm(5) Wallace,GregoryK."TheJPEGStillPictureCompressionStandard",Communicationsofthe ACM,April1991(vol.34,no.4),pp.30-44. AUTHOR IndependentJPEGGroup 12December1994 3 CJPEG(1) CJPEG(1) BUGS Arithmeticcodingisnotsupportedforlegalreasons. NotallvariantsofBMPandTargafileformatsaresupported. The−targaswitchisnotabug,it’safeature.(ItwouldbeabugiftheTargaformatdesigners hadnotbeenclueless.) Stillnotasfastaswe’dlike. 12December1994 4